home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_shs_switchdoors.cog < prev    next >
Text File  |  1999-11-15  |  5KB  |  244 lines

  1. # Jones 3D Cog Script
  2. #
  3. # shs_SwitchDoors.cog
  4. #
  5. # Bulletproofed Two-Way Door Script
  6. #
  7. # [RT & CMG]
  8. #
  9. # (C) 1999 LucasArts Entertainment Co. LLC All Rights Reserved
  10. # ===================================================================
  11. symbols
  12.  
  13. message    startup
  14. message    activated
  15. message    arrived
  16. message    touched
  17. message    timer
  18.  
  19. # ************************* SOUNDS *************************
  20.  
  21. sound    click=sol_panel_switch_c.wav        local
  22. sound    open_squeak=sea_doors_open_c.wav    local
  23. sound    close_squeak=sea_doors_close_c.wav    local
  24.  
  25. # ************************* THINGS *************************
  26.  
  27. thing    door
  28. thing    button0
  29. thing    button1
  30.  
  31. thing    player            local
  32. thing    sender            local
  33.  
  34. # *********************** MISCELLANY ***********************
  35.  
  36. sector    doorSector        local
  37.  
  38. flex    doorTime=1.0    local
  39. flex    sleepTime=3.0    local
  40.  
  41. flex    rotDegrees        local
  42. flex    doorYaw               local
  43.  
  44. flex    tempFlex        local
  45.  
  46. int        open=0            local # closed = 0; opening = 1; open = 2; closing = 3
  47. int        notnow=0        local
  48. int        bTouched=0        local
  49.  
  50. vector    doorPos            local
  51. vector    closedPYR        local
  52. vector    openPYR            local
  53.  
  54. vector    tempVec            local
  55.  
  56. # ********************** SUBROUTINES ***********************
  57.  
  58. flex    OpenDoors        local
  59. flex    CloseDoors        local
  60.  
  61. end
  62.  
  63. # ===================================================================
  64.  
  65. code
  66.  
  67. startup:
  68.  
  69.     player = GetLocalPlayerThing();
  70.     doorSector = GetThingSector(door);
  71.     doorPos = GetThingPos(door);
  72.     closedPYR = GetThingLVecPYR(door);
  73.     SetSectorAdjoins(doorSector, 0);
  74.     return;
  75.  
  76. # -------------------------------------------------------------------
  77.  
  78. activated:
  79.  
  80.     if (notnow) return;
  81.  
  82.     notnow = 1;
  83.  
  84.     sender = GetSenderRef();
  85.  
  86.     if (sender == button0)
  87.     {
  88.         rotDegrees = 90;
  89.     }
  90.     else if (sender == button1)
  91.     {
  92.         rotDegrees = -90;
  93.     }
  94.     else
  95.     {
  96.         notnow = 0;
  97.         return;
  98.     }
  99.  
  100.     # Disable player control
  101.     SetActorFlags(player, 0x200000);
  102.     StopThing(player);
  103.     StartCutscene(0);
  104.     Sleep(0.1);
  105.  
  106.     # Turn on adjoins
  107.     SetSectorAdjoins(doorSector, 1);
  108.  
  109.     # Animate the player & wait...
  110.     PlayMode(player, 60, 1);
  111.  
  112.     # Player regains control
  113.     ClearActorFlags(player, 0x200000);
  114.     EndCutscene();
  115.  
  116.     # Play sounds, move the buttons and door
  117.     MoveToFrame(button0, 1, 1);
  118.     MoveToFrame(button1, 1, 1);
  119.     PlaySoundThing(click, button0, 1, 3, 10, 0x0);
  120.     Sleep(0.25);
  121.  
  122.     call OpenDoors;
  123.  
  124.     return;
  125.  
  126. # -------------------------------------------------------------------
  127.  
  128. arrived:
  129.  
  130.     if (GetSenderRef() != door) return;
  131.  
  132.     if (open == 1)
  133.     {
  134.         open = 2;
  135.  
  136.         openPYR = GetThingLVecPYR(door);
  137.         SetTimer(sleepTime);
  138.     }
  139.     else if ((open == 3) && (!bTouched))
  140.     {
  141.         MoveToFrame(button0, 0, 1);
  142.         MoveToFrame(button1, 0, 1);
  143.  
  144.         PlaySoundThing(click, door, 1, 3, 10, 0x0);
  145.  
  146.         tempFlex = VectorY(GetThingLVecPYR(door));
  147.         if (Truncate(tempFlex) == 0);
  148.         {
  149.             # Slam door into closed position
  150.             SetThingPos(door, doorPos);
  151.             SetThingLVecPYR(door, closedPYR);
  152.         }
  153.  
  154.         # Turn off adjoins
  155.         SetSectorAdjoins(doorSector, 0);
  156.  
  157.         open = 0;
  158.         notnow = 0;
  159.     }
  160.  
  161.     return;
  162.  
  163. # -------------------------------------------------------------------
  164.  
  165. touched:
  166.  
  167.     if (open != 3) return;
  168.  
  169.     if (GetSenderRef() != door) return;
  170.  
  171.     # See if Indy's behind the door...
  172.     tempVec = VectorSub(GetThingPos(door), GetThingPos(player));
  173.     tempVec = VectorNorm(tempVec);
  174.     tempFlex = VectorDot(tempVec, GetThingLVec(door));
  175.     if (tempFlex > 0)
  176.     {
  177.         if (rotDegrees > 0) return;
  178.     }
  179.     else
  180.     {
  181.         if (rotDegrees < 0) return;
  182.     }
  183.  
  184.     bTouched = 1;
  185.     open = 1;
  186.  
  187.     # Stop rotation and wait for engine to update
  188.     StopThing(door);
  189.     Sleep(0.1);
  190.  
  191.     # Calculate door yaw
  192.     tempFlex = VectorY(GetThingLVecPYR(door));
  193.     tempFlex = Abs(tempFlex);
  194.  
  195.     if (rotDegrees < 0)
  196.     {
  197.         doorYaw = 90 - tempFlex;
  198.     }
  199.     else
  200.     {
  201.         doorYaw = tempFlex - 90;
  202.     }
  203.  
  204.     # Calculate time to reopen door
  205.     tempFlex = Abs(doorYaw) / 90;
  206.     tempFlex = doorTime * tempFlex;
  207.  
  208.     # Open it back up...
  209.     Rotate(door, doorYaw, 1, tempFlex); 
  210.  
  211.     return;
  212.  
  213. # -------------------------------------------------------------------
  214.  
  215. timer:
  216.  
  217.     call CloseDoors;
  218.     return;
  219.  
  220. # -------------------------------------------------------------------
  221.  
  222. OpenDoors:
  223.  
  224.     Rotate(door, rotDegrees, 1, doorTime);
  225.     PlaySoundThing(open_squeak, door, 1, 3, 10, 0x0);
  226.     bTouched = 0;
  227.     open = 1;
  228.     return;
  229.  
  230. # -------------------------------------------------------------------
  231.  
  232. CloseDoors:
  233.  
  234.     Rotate(door, -rotDegrees, 1, doorTime);
  235.     PlaySoundThing(close_squeak, door, 1, 3, 10, 0x0);
  236.     bTouched = 0;
  237.     open = 3;
  238.     return;
  239.  
  240. # -------------------------------------------------------------------
  241.  
  242. end
  243.  
  244.